<template>
  <div>
    <h2>我是首页</h2>
    <p>我是首页内容</p>

    <router-link to="/home/news">新闻</router-link>
    <router-link to="/home/message">消息</router-link>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      path: '/home/news'
    }
  },
  activated() {
    // activated() 和 deactivated()只有在keep-alive包裹router-view后才会执行
    console.log('activated');
    this.$router.push(this.path)
  },
  beforeRouteLeave(to, from , next) {
    console.log('beforeRouteLeave');
    console.log(this.$route.path)
    this.path = this.$route.path
    next()
  },
  created() {
    console.log('Home create');
  },
  deactivated() {
    console.log('Home deactivated');
  }
}
</script>

<style scoped>

</style>
